package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class BibliotecaApp {

    public static void main(String[] args) {
        BibliotecaController bc = new BibliotecaController();


        Library library = new Library();
        List<LibraryOption> options = new ArrayList<LibraryOption>();

        ListingBookOption listingBookOption = new ListingBookOption(library);
        options.add(listingBookOption);
        CheckoutBookOption checkoutBookOption = new CheckoutBookOption(library);
        options.add(checkoutBookOption);
        ReturnBookOption returnBookOption = new ReturnBookOption(library);
        options.add(returnBookOption);
        ListingMovieOption listingMovieOption = new ListingMovieOption(library);
        options.add(listingMovieOption);
        CheckoutMovieOption checkoutMovieOption = new CheckoutMovieOption(library);
        options.add(checkoutMovieOption);
        UserInfoOption userInfoOption = new UserInfoOption(library);
        options.add(userInfoOption);
        LoginOption loginOption = new LoginOption(library);

        Menu menu = new Menu(options);

        System.out.println(bc.welcome());
        System.out.println("Enter ID:");
        Scanner scID = new Scanner(System.in);
        String userId = scID.nextLine();
        System.out.println("Enter Password:");
        Scanner scPassword = new Scanner(System.in);
        String password = scPassword.nextLine();

        if (bc.login(loginOption, userId, password)) {
            System.out.println("Here is the options of Bibliotca:");

            System.out.println(bc.displayOptions(menu.getLibraryOptions()));

            while (true) {
                System.out.println("\nPlease enter an option:");

                Scanner sc = new Scanner(System.in);
                String inputOption = sc.nextLine();

                if (inputOption.toLowerCase().equals("quit")) {
                    bc.quit();
                } else if (inputOption.toLowerCase().equals("book checkout")) {
                    String bookCheckedOut = new Scanner(System.in).nextLine();
                    System.out.println(bc.checkoutBook(checkoutBookOption, bookCheckedOut, library.getOwnedUser(userId, password)));
                } else if (inputOption.toLowerCase().equals("return book")) {
                    String bookReturned = new Scanner(System.in).nextLine();
                    System.out.println(bc.returnBook(returnBookOption, bookReturned));
                } else if (inputOption.toLowerCase().equals("list books")) {
                    System.out.println("Book List:");
                    System.out.println(bc.listBook(listingBookOption));
                } else if (inputOption.toLowerCase().equals("list movies")) {
                    System.out.println("Movie List:");
                    System.out.println(bc.listMovie(listingMovieOption));
                } else if (inputOption.toLowerCase().equals("movie checkout")){
                    String movieCheckout = new Scanner(System.in).nextLine();
                    System.out.println(bc.checkoutMovie(checkoutMovieOption, movieCheckout));
                } else if (inputOption.toLowerCase().equals("user info")) {
                    System.out.println(bc.userInfo(userInfoOption, userId, password));
                }
                else {
                    System.out.println(bc.invalidOption());
                }

            }

        }

    }
}
